﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace GlobalizationTest
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        /// <summary>  
        /// Set the resource culture  
        /// </summary>  
        private void SetResourceCulture()
        {
            // Set the form title text  
            this.Text = ResourceCulture.GetString("Form1_frmText");

            // Set the groupbox text  
            this.gbLanguageView.Text = ResourceCulture.GetString("Form1_gbLanguageViewText");
            this.gbLanguageSelection.Text = ResourceCulture.GetString("Form1_gbLanguageSelectionText");

            // Set the label text  
            this.lblCurLanguageText.Text = ResourceCulture.GetString("Form1_lblCurLanguageText");
            this.lblNameText.Text = ResourceCulture.GetString("Form1_lblNameText");
            this.lblPhoneText.Text = ResourceCulture.GetString("Form1_lblPhoneText");

            // Set the button text  
            this.btnMsgShow.Text = ResourceCulture.GetString("Form1_btnMsgShowText");

            // Set radiobutton text  
            this.rbEnglish.Text = ResourceCulture.GetString("Language_EnglishText");
            this.rbChinese.Text = ResourceCulture.GetString("Language_ChineseText");

            // Set the current language text  
            if (rbEnglish.Checked)
            {
                this.lblCurLanguage.Text = ResourceCulture.GetString("Language_EnglishText");
            }
            else if (rbChinese.Checked)
            {
                this.lblCurLanguage.Text = ResourceCulture.GetString("Language_ChineseText");
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            // Set the default language  
            ResourceCulture.SetCurrentCulture("en-US");
            rbEnglish.Select();
            this.SetResourceCulture();  
        }

        private void btnMsgShow_Click(object sender, EventArgs e)
        {
            if(string.IsNullOrEmpty(txtName.Text))  
            {  
                MessageBox.Show(ResourceCulture.GetString("Form1_msgbox_nameText"), ResourceCulture.GetString("Form1_msgbox_TitleText"),   
                    MessageBoxButtons.OK, MessageBoxIcon.Exclamation);  
                return;  
            }  
  
            if (string.IsNullOrEmpty(txtPhone.Text))  
            {  
                MessageBox.Show(ResourceCulture.GetString("Form1_msgbox_phoneText"), ResourceCulture.GetString("Form1_msgbox_TitleText"),   
                    MessageBoxButtons.OK, MessageBoxIcon.Exclamation);  
                return;  
            }

            MessageBox.Show(ResourceCulture.GetString("Form1_msgbox_InfoText") + ":" + txtName.Text + ", " + txtPhone.Text,
                ResourceCulture.GetString("Form1_msgbox_TitleText"), MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

        private void rbEnglish_CheckedChanged(object sender, EventArgs e)
        {
            ResourceCulture.SetCurrentCulture("en-US");
            this.SetResourceCulture();  
        }

        private void rbChinese_CheckedChanged(object sender, EventArgs e)
        {
            ResourceCulture.SetCurrentCulture("zh-CN");
            this.SetResourceCulture();  
        }  
        
    }
}
